package com.system.weirdor.crawler.pipline;

import com.system.weirdor.search.index.EsBlog;
import com.system.weirdor.search.service.EsBlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.List;
import java.util.Map;
import java.util.UUID;


/**
 * @author weirdor
 *
 */
@Repository
public class CnBlogPinPipeline  implements Pipeline {
    @Autowired
    EsBlogService esBlogRepository;
	public void process(ResultItems resultItems, Task task) {
        System.out.println("get page: " + resultItems.getRequest().getUrl());
        for (Map.Entry<String, Object> entry : resultItems.getAll().entrySet()) {
            System.out.println(entry.getKey()+">>"+entry.getValue());
            List<EsBlog> list=null;
            EsBlog esBlog=new EsBlog();
            if (entry.getKey().contains("content")){
                esBlog.setContent(entry.getValue().toString());
            }
            if (entry.getKey().contains("title")){
                esBlog.setTitle(entry.getValue().toString());
            }
            esBlog.setId(UUID.randomUUID().toString());
            System.err.println(esBlog);
            esBlogRepository.save(esBlog);
            System.err.println(list);
        }
       
    }

    }


